package NC;

public class NC53 {
    public ListNode removeNthFromEnd (ListNode head, int n) {
        // write code here
        if(head==null) return null;
        ListNode dummy = new ListNode(0);
        dummy.next = head;
        ListNode pre = dummy, post = dummy;
        int index = 0;
        while (post != null) {
            if(index>n){
                pre=pre.next;
            }
            post =post.next;
            index++;
        }
        pre.next =  pre.next.next;
        return dummy.next;
    }
}
